<script>
import { pageMixin } from '@/mixins/index'
import addOrUpdate from './add_or_update.vue'
export default {
  name: 'EarlyWarning',
  components: { addOrUpdate },
  mixins: [pageMixin],
  data() {
    return {
      tableData: [],
      loading: false,
      form: {

      }
    }
  },
  created() {
    this.getTableData()
  },
  methods: {
    /**
     * 获取数据
     */
    getTableData() {
      // TODO:调用接口，然后赋值
    },
    /**
     * 新增
     */
    addedHandle() {
      this.$refs.popupRef.init()
    },
    /**
     * 修改
     * @param {Object} data
     */
    modifyHandle(data) {
      this.$refs.popupRef.init(data)
    },
    /**
     * 删除
     * @param {number} id
     */
    deleteHandle(id) {
    },
    /**
     * 重置
     */
    rest(formName) {
      console.log(this.$refs[formName])
      this.$refs[formName].resetFields()
      this.getTableData()
    }
  }
}
</script>
<template>
  <el-card>
    <el-form ref="searchRef" :model="form" inline label-width="90px">
      <el-form-item label="物料名称" prop="name">
        <el-input v-model="form.name" />
      </el-form-item>
      <el-form-item label="检验项目" prop="address">
        <el-input v-model="form.address" />
      </el-form-item>
      <el-form-item label="检验类型" prop="state">
        <el-select v-model="form.state">
          <el-option v-for="item in getStateOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <template>
          <el-button @click="rest('searchRef')">重置</el-button>
          <el-button type="primary" @click="getTableData">搜索</el-button>
          <el-button type="primary" @click="addedHandle">新增</el-button>
        </template>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="tableData" :border="true">
      <el-table-column label="编号" prop="id" />
      <el-table-column label="物料名称" />
      <el-table-column label="型号" />
      <el-table-column label="规格" />
      <el-table-column label="单位" />
      <el-table-column label="检验项目" />
      <el-table-column label="检验类型" />
      <el-table-column label="标准值上限" />
      <el-table-column label="标准值下限" />
      <el-table-column label="操作" fixed="right" width="150">
        <template v-slot="scope">
          <el-button type="success" size="small" plain round @click="modifyHandle(scope.row)">修改</el-button>
          <el-button type="danger" size="small" plain round @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="formPage.page"
      :page-sizes="[10, 20, 30, 50]"
      :page-size="formPage.size"
      :total="total"
      background
      layout="total, sizes, prev, pager, next, jumper"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <add-or-update ref="popupRef" @updateData="getTableData" />
  </el-card>
</template>
